import React, { Component } from 'react';
import Coma from './Coma';

class Ref extends Component {
  constructor() {
    super();
    this.state = {

    }
    // 创建ref
    this.divRef = React.createRef()
    this.comaRef = React.createRef()
    this.inputRef = React.createRef()
  }
  componentDidMount() {
    console.log(this.divRef.current);
    this.divRef.current.innerHTML = '666';
    console.log(222, this.comaRef.current.state.age);
  }
  submit() {
    // 获取用户上传的文件
    console.log(this.inputRef.current.files);
  }
  render() {
    return (
      <div>
        <p>Ref:指向一个元素或者组件，作用类似选择器</p>
        <div ref={this.divRef}>我是一个div</div>
        <Coma ref={this.comaRef}></Coma>
        <input ref={this.inputRef} type="file"></input>
        <button onClick={()=>this.submit()}>提交</button>
      </div>
    );
  }
}

export default Ref;
